function[data] = read_iaga2002_1min(fname)
% These scripts were written to read 1 minute electric field
% data from Kakioka obs


   fid = fopen(fname,'r');

   

   if fid == -1,

      error(sprintf('Unable to open <%s>',fname));

   end


      [S] = fgetl(fid);%  Format                 IAGA-2002    

      [S] = fgetl(fid);%  Source of Data         IPGP                                         |

      [S] = fgetl(fid);%  Station Name           ADDIS ABABA                                  |

      [S] = fgetl(fid);%  IAGA CODE              AAE                                          |

      ID = sscanf(S,'%*s%*s%s');

      [S] = fgetl(fid);%  Geodetic Latitude      09.033                                       |

      LAT = sscanf(S,'%*s%*s%f');

      [S] = fgetl(fid);%  Geodetic Longitude     038.767                                      |

      LON = sscanf(S,'%*s%*s%f');

      [S] = fgetl(fid);%  Elevation              2442                                         |

      [S] = fgetl(fid);%  Reported               XYZF                                         |

      coords0 = sscanf(S,'%*s%s');

      [S] = fgetl(fid);%  Sensor Orientation     HDZF                                         |

      [S] = fgetl(fid);%  Digital Sampling       1 minute   

      sampling = sscanf(S,'%*s%*s%s');

      [S] = fgetl(fid);%  Data Interval Type     Filtered 1-minute (00:30 - 01:29)            |

      [S] = fgetl(fid);%  Data Type              definitive                                   |

      [S] = fgetl(fid);%  This file was converted from the INTERMAGNET CD-ROM binary data   |


      fclose(fid);
        
        

[date,hms,a,X,Y,Z] = textread(fname,'%s %s %f %f %f %f %*f','headerlines',20,'delimiter',' ');


    %deal with the missing data

    

    X(X >= 88888.00) = NaN;

    Y(Y >= 88888.00) = NaN;

    Z(Z >= 88888.00) = NaN;


    A = cell2mat(date(1));

    B = cell2mat(hms(1));

    startfday = datenum([A ' ' B(1:6) '00'],31);

    MINUTELY(:,1) = startfday:(1/1440):(startfday + (length(X) - 1) /1440);


    %minutely, first array is matlab time (have follow the INTERMAG.m)      


    MINUTELY(:,[2 3]) = [X Y];

    

    MINUTELY(:,4) = Z;

    data = struct('MINUTELY',MINUTELY);
    
    data.LAT = LAT;
    data.LON = LON;
    data.CODE = ID;







%------------------------------------

